﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using AnguaRPGEngine.Library.Configuration;
namespace AnguaRPGEngine.Library.Forms
{
    public partial class BookmarkEditor : Form
    {
        private string _fileSpec;
        private Bookmark _bookmark;
        public Bookmark Bookmark
        {
            get
            {
                return _bookmark;
            }
        }
        public BookmarkEditor(string bookFilespec, Bookmark bookMark)
        {
            _bookmark = bookMark;
            if (_bookmark == null)
            {
                _bookmark = new Configuration.Bookmark();
                _bookmark.Page = "";
                _bookmark.OpenCommand = "";
                _bookmark.Name = "";
            }
            _fileSpec = bookFilespec;
            
            InitializeComponent(); 
            
            txtPage.Text = _bookmark.Page;
                txtName.Text = _bookmark.Name;
                txtOpenCommand.Text = _bookmark.OpenCommand;
           
            

        }
        #region Overrides For Background Painting And Resizing

        //const int WM_NCHITTEST = 0x0084;
        //const int HTCLIENT = 1;
        //const int HTCAPTION = 2;
        //protected override void WndProc(ref Message m)
        //{
        //    base.WndProc(ref m);
        //    switch (m.Msg)
        //    {
        //        case WM_NCHITTEST:
        //            if (m.Result == (IntPtr)HTCLIENT)
        //            {
        //                m.Result = (IntPtr)HTCAPTION;
        //            }
        //            break;
        //    }
        //}
        //protected override void OnPaint(PaintEventArgs e)
        //{
        //    base.OnPaint(e);
        //    e.Graphics.FillRectangle(new LinearGradientBrush(new Point(0, 0), new Point(this.Width, 15), Color.DarkBlue, Color.Blue), new Rectangle(0, 0, this.Width, 15));
        //    e.Graphics.DrawLine(new Pen(new SolidBrush(Color.DarkGray), 1f), new Point(0, 16), new Point(this.Width, 16));
        //    e.Graphics.DrawString(this.Text, this.Font, new SolidBrush(Color.White), new PointF(0, 0));

        //}
        //protected override CreateParams CreateParams
        //{
        //    get
        //    {
        //        CreateParams cp = base.CreateParams;
        //        cp.Style |= 0x40000;

        //        return cp;
        //    }
        //}
        #endregion
     
        private void txtPage_TextChanged(object sender, EventArgs e)
        {
            if (_fileSpec.ToUpper().EndsWith(".PDF"))
            {
                txtOpenCommand.Text = Bookmark.AdobeOpenCommand(txtPage.Text, _fileSpec);
            }
            _bookmark.Page = txtPage.Text;
        }

        private void txtName_TextChanged(object sender, EventArgs e)
        {
            _bookmark.Name = txtName.Text;
        }

        private void txtOpenCommand_TextChanged(object sender, EventArgs e)
        {
            _bookmark.OpenCommand = txtOpenCommand.Text;
        }

    }
}
